<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: snow_header"></head>
<body class="gray-bg">
    <div class="container-div">
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="bootstrapTable.operateAdd()" shiro:hasPermission="module:OSSConfig:add">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-outline btn-danger btn-rounded" onclick="bootstrapTable.operateRemoveAll()" shiro:hasPermission="module:OSSConfig:remove">
				<i class="fa fa-trash-o"></i> 删除
			</a>
		</div>
			
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap"></table>
		</div>
    </div>
	<div th:include="include :: snow_footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module:ossconfig:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:ossconfig:remove')}]];
		var releaseFlag = [[${@permission.hasPermi('module:ossconfig:release')}]];
        var prefix = ctx + "module/ossconfig";

        var columnVisible=editFlag=='hidden'?'gone':'visible'
		columnVisible=editFlag=='hidden'?false:true

		var bootstrapTable=$.snowBootstrap.init("bootstrap-table");
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
				copyUrl: prefix + "/copy/{id}",
                removeUrl: prefix + "/remove",
                modalName: "阿里云OSS资源",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'ossConfigId', 
					title : '主键'
				},
                {
                    field : 'description',
                    title : '描述'
                },
				{
					field : 'accessKeyId', 
					title : '访问密钥'
					,visible: columnVisible
				},
				{
					field : 'secretAccessKey', 
					title : '秘密访问密钥'
					,visible: columnVisible
				},
				{
					field : 'endpoint', 
					title : '节点名称'
					,visible: columnVisible
				},
				{
					field : 'bucketName', 
					title : '存储空间名称'
					// ,visible: columnVisible
				},
				{
					field : 'fileName', 
					title : 'OSS文件名称'
					// ,visible: columnVisible
				},
				{
					field : 'ossContentType', 
					title : 'OSS内容类型'
					,visible: columnVisible
				},
				// {
				// 	field : 'fileContentStr',
				// 	title : '文件内容'
				// },
				{
					field : 'updateBy',
					title : '更新者'
				},
				{
					field : 'updateTime', 
					title : '更新时间' 
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						actions.push('<a class="btn btn-danger btn-xs ' + releaseFlag + '" href="#" onclick="editContent(\'' + row.ossConfigId + '\')"><i class="fa fa-edit"></i>内容编辑</a>');
						actions.push('<a class="btn btn-primary btn-xs ' + releaseFlag + '" href="#" onclick="release(\'' + row.ossConfigId + '\')"><i class="fa fa-cloud-upload"></i>发布</a>');
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="bootstrapTable.operateEdit(\'' + row.ossConfigId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="bootstrapTable.operateCopy(\'' + row.ossConfigId + '\')"><i class="fa fa-copy"></i>复制</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="bootstrapTable.operateRemove(\'' + row.ossConfigId + '\')"><i class="fa fa-remove"></i>删除</a>');

						return actions.join('');
		            }
		        }]
            };
            console.log("options=",options);
			console.log("editFlag=",editFlag);
            // $.table.init(options);
			bootstrapTable.tableInit(options);
        });
		function editContent(id) {
			var url = prefix + "/content/"+id;
			$.modal.openFull("内容编辑" , url,600,600);
		}

		function release(id) {
			$.modal.confirm("确定要发布到阿里云吗?", function() {
				layer.msg('执行成功,正在生成代码并上传,请稍后…', { icon: 1 });
				var config = {
					url:  prefix+"/release/"+id,
					type: "post",
					success: function(result) {
						if (result.code == web_status.SUCCESS) {
							$.modal.alertSuccess(result.msg);
						} else {
							$.modal.alertError(result.msg);
						}
					}
				};
				$.ajax(config);
			})
		}


    </script>
</body>
</html>